package com.zr.bookcorner.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.zh.baselibrary.constant.BaseConstant;
import com.zh.baselibrary.netutils.NetUtil;
import com.zh.baselibrary.utils.DisplayUtil;
import com.zh.baselibrary.utils.PhoneUtil;
import com.zh.baselibrary.utils.ShareManager;
import com.zh.model.EquipmentLogin;
import com.zh.model.home.QrCodeBean;


/**
 * @author EnzoChan
 * @create 2019/3/10
 * @desc:
 */
public class DeviceUtil {

    public static Bitmap getDeviceInfo(Context context) {
        String uuid = PhoneUtil.getUUID(context);
        String version = "" + PhoneUtil.getLocalVersion(context);

        String netType = NetUtil.getNetType(context);

        String lineNumber = PhoneUtil.getLineNumber(context);


        String location = ShareManager.getValue(context, BaseConstant.DEVICE_LOCATION);
        QrCodeBean mBean = new QrCodeBean();


        mBean.setNetType(netType);
        mBean.setEquipmentCode(uuid);
        mBean.setCardCode(lineNumber);
        mBean.setVersion(version);
        mBean.setMainProgramVersionName(PhoneUtil.getVersionName(context));
        mBean.setEquipmentType(0);
        mBean.setLocation(location);
        String type = ShareManager.getValue(context,BaseConstant.DEVICE_TYPE);
        if(TextUtils.isEmpty(type))
            type = "MXYG-16N";
        mBean.setDeviceType(type);

        mBean.setIp(NetUtil.getIPAddress(context));

        Gson mGson = new Gson();

        String content = mGson.toJson(mBean);

        Point mPoint = DisplayUtil.getScreenMetrics(context);

        Bitmap bmQR = ZXingUtils.createQRImage(content, mPoint.x, mPoint.y);

//        Bitmap bmLogo = BitmapFactory.decodeResource(context.getResources(), R.mipmap.logo);


        return bmQR;
    }
    public static EquipmentLogin getEquipmentLogin(Context context){
        return  new EquipmentLogin(PhoneUtil.getIccID(context),PhoneUtil.getUUID(context),PhoneUtil.getLocalVersion(context),"v"+PhoneUtil.getVersionName(context));
    }

    public static QrCodeBean getDeviceBean(Context context) {
        String uuid = PhoneUtil.getUUID(context);
        String version = "" + PhoneUtil.getLocalVersion(context);

        String netType = NetUtil.getNetType(context);

        String lineNumber = PhoneUtil.getLineNumber(context);


        String location = ShareManager.getValue(context, BaseConstant.DEVICE_LOCATION);

        QrCodeBean mBean = new QrCodeBean();

        mBean.setLocation(location);
        mBean.setNetType(netType);
        mBean.setEquipmentCode(uuid);
        mBean.setCardCode(lineNumber);
        mBean.setVersion(version);
        mBean.setEquipmentType(0);
        String type = ShareManager.getValue(context,BaseConstant.DEVICE_TYPE);
        if(TextUtils.isEmpty(type))
            type = "MXYG-16N";
        mBean.setDeviceType(type);
        mBean.setSchoolId(ShareManager.getValue(context, BaseConstant.DEVICE_SCHOOL_ID));
        mBean.setSchoolName(ShareManager.getValue(context, BaseConstant.DEVICE_SCHOOL_NAME));
        mBean.setId(ShareManager.getLong(context, BaseConstant.DEVICE_ID));
        mBean.setVoiceSwitch(ShareManager.getInt(context, BaseConstant.DEVICE_VOICE));
        mBean.setIp(NetUtil.getIPAddress(context));

        return mBean;
    }

}
